/*  KKS - KinoKassenSystem 2013
 * 
 *  author Sebastian Schöppner
 * 
 *  panel containing movie information
 * 
 *  
 */
package kks;

import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.plaf.BorderUIResource;

public class PanelMovie extends JPanel
{
    private Dimension dimDefault = new Dimension(200, 550);
    private ArrayList<GregorianCalendar> MovieTimes;
    private ArrayList<JButton> ButtonList = new ArrayList<>();
    
    private JLabel lblMovieName;
    private JLabel lblMovieRoom;
    private JLabel lblMovieTimes;
    private JLabel lblSeats;
    private JLabel lblPic;
    private JLabel lblPrice;
    private int cnt = 0;
    private cMovie Movie;
    private HomeFrame HomeFrame;

    
    /**
     * 
     * 
     * Create a new buffered PanelMovie
     *
     * @param frame containing the panel
     * @param movie  the movie to  create
     */
    public PanelMovie(HomeFrame homeFrame,cMovie movie) //final HomeFrame frame, String movieName, double price, int movieRoom, ArrayList<String> movieTimes, int rows, int seats) {
    {
        setLayout(new GridBagLayout());
        //setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
        //setMinimumSize(dimDefault);
        setPreferredSize(dimDefault);        
        
        Border border = new BorderUIResource.LineBorderUIResource(CustomColors.Highlight, 1);
        setBorder(border);

        Movie = movie;
        HomeFrame = homeFrame;
        
        lblMovieName = new JLabel(movie.getMovieName());
        lblMovieName.setPreferredSize(dimDefault);
        lblMovieName.setFont(CustomFonts.FontSubline);
        lblMovieRoom = new JLabel("Room: " + Integer.toString(movie.getMovieRoom()));
        lblMovieRoom.setPreferredSize(dimDefault);
        lblMovieRoom.setFont(CustomFonts.FontSubline);
        lblSeats = new JLabel("Seats: " +  Integer.toString(movie.getRows()*movie.getSeats()));
        lblSeats.setFont(CustomFonts.FontSubline);
        lblPrice = new JLabel(movie.getPriceString() + " EUR");
        
        lblPic = new JLabel(new ImageIcon(getClass().getResource("/images/poster/"+movie.getMovieName()+".jpg")));
        
        //add time buttons
        for (int i = 0; i < movie.getTimes().size(); i++)
        {
            
            String StringDate = Integer.toString(movie.getTimes().get(i).get(Calendar.HOUR_OF_DAY)) + ":" + Integer.toString(movie.getTimes().get(i).get(Calendar.MINUTE)) + "0";
            ButtonList.add(new JButton(StringDate));
            ButtonList.get(i).setPreferredSize(new Dimension(200, 50));
            ButtonList.get(i).addActionListener(new ActionListener() 
            {

                @Override
                public void actionPerformed(ActionEvent e) 
                {
                    //
                    Movie.selectSeats(HomeFrame);

                }
            });
        }
    
        LayoutHelper.addComponent(this,(GridBagLayout)getLayout(), lblMovieName,      0, 0, 5, 1, 0, 0, 10);
        LayoutHelper.addComponent(this,(GridBagLayout)getLayout(), lblPic,          0, 1, 5, 5, 0, 0, 10);
        
        LayoutHelper.addComponent(this,(GridBagLayout)getLayout(), lblMovieRoom,      0, 7, 2, 1, 0, 0, 10);
        LayoutHelper.addComponent(this,(GridBagLayout)getLayout(), lblSeats,          3, 7, 1, 1, 0, 0, 10);
        LayoutHelper.addComponent(this,(GridBagLayout)getLayout(), lblPrice,          0, 8, 1, 1, 1, 1, 10);
        
        //add all timeButtons
        for (int i=0;i<ButtonList.size()-1;i++)
        {
            LayoutHelper.addComponent(this,(GridBagLayout)getLayout(), ButtonList.get(i), 0, 9+i, 4, 1, 1, 1, 10);            
        }
        
    }
    
    /** 
     * set moviename to the label
     *
     * @param moviename
     */    
    public final void setMovieName(String movieName)
    {
        lblMovieName.setText(movieName);
    }
    
    /** 
     * set room to the label
     *
     * @param roomnumber
     */        
    public final void setMovieRoom(int movieRoom)
    {
        lblMovieRoom.setText(Integer.toString(movieRoom));
    }

     /** 
     * set movietimes
     *
     * @param array of the movietimes
     */    
    public final void setMovieTimes(ArrayList<GregorianCalendar> movieTimes)
    {
            MovieTimes = movieTimes;
    }
    
    /** 
     * set movie seats
     *
     * @param count of seats
     */        
    public final void setSeats(int value)
    {
        lblSeats.setText(Integer.toString(value));
    }
    
    /** 
     * set movieprice to the label
     *
     * @param price
     */       
    public final void setPrice(double value)
    {
        lblPrice.setText(Double.toString(value));
    }
    
}
